#include <random>
#include "tracker1D_api.h"

int test_tracker1D()
{
	we_f32 fs = 2e6f;
	we_f32 bw = 1.883e6f * 2048.f;
	we_f32 dr = 3e8f / 2.f / bw;

	we_f32 zs[] = {
50.48703,
50.48753,
50.48703,
50.48703,
50.48703,
50.48753,
50.48653,
50.48703,
50.48703,
50.48753,
50.48653,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48753,
50.48703,
50.48703,
50.48753,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48653,
50.48653,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48653,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48753,
50.48703,
50.48703,
50.48703,
50.48703,
50.48753,
50.48703,
50.48703,
50.48753,
50.48753,
50.48653,
50.48753,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48753,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48753,
50.48703,
50.48703,
50.48703,
50.48653,
50.48653,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48753,
50.48653,
50.48703,
50.48753,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48653,
50.48703,
50.48753,
50.48653,
50.48653,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48653,
50.48703,
50.48753,
50.48703,
50.48653,
50.48653,
50.48703,
50.48703,
50.48703,
50.48753,
50.48703,
50.48753,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48753,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48653,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48653,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48753,
50.48703,
50.48703,
50.48703,
50.48703,
50.48653,
50.48653,
50.48553,
50.48703,
50.48753,
50.48703,
50.48653,
50.48703,
50.48653,
50.48653,
50.48703,
50.48653,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48703,
50.48753,
50.48703,
50.48703,
50.48703,
	};

	tracker1D_init(dr);

	std::default_random_engine generator;
	std::normal_distribution<double> distribution(50.4, 0.01);

	FILE* fid = fopen("ans.csv", "wt");
	for (int i = 0; i < 255; ++i)
	{
		we_f32 inp[2];
		inp[1] = zs[i];
		inp[0] = distribution(generator);
		auto n = tracker1D_tracking(inp, 2, 1);
		auto outs = tracker1D_get_output();


		fprintf(fid, "-1, %.4f\n", inp[0]);
		fprintf(fid, "-2, %.4f\n", inp[1]);
		for (int j = 0; j < n; ++j)
		{
			fprintf(fid, "%d, %.4f\n", outs->m_data[j].m_id, outs->m_data[j].m_distance);
		}
		//fprintf(fid, "\n");

		printf("%d %d: \n", i, n);
		for (int j = 0; j < n; ++j)
		{
			printf("\t[%d, %.4f, %.4f]\n", outs->m_data[j].m_id, outs->m_data[j].m_distance, outs->m_data[j].m_velocity);
		}
		printf("\n");
	}
	fclose(fid);

	return 0;
}